package org.gitman.agentplatform.agent.impl.activator;

import org.gitman.agentplatform.agent.impl.AgentFactoryImpl;
import org.gitman.agentplatform.core.services.AgentFactoryRegistrationService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class Activator implements BundleActivator {

	private static BundleContext context;

	static BundleContext getContext() {
		return context;
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
		ServiceReference<?> serviceReference = context.getServiceReference(AgentFactoryRegistrationService.class);
		AgentFactoryRegistrationService service = (AgentFactoryRegistrationService) context.getService(serviceReference);
		//service.addFactory(new AgentFactoryTest1Impl());
		//service.addFactory(new AgentFactoryTest2Impl());
		service.addFactory(new AgentFactoryImpl());
		System.out.println("[AgentImpl]\tstarted");		
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
	}

}
